package com.redis.threadlock;

/**
 * 不可重入锁
 * @author WLZ
 *
 */
public class Lock {
	
	private boolean isLocked = false;
	
	public synchronized void lock() {
		System.out.println(Thread.currentThread().getName()+" :当前线程进入");
		while (isLocked) {
			try {
				System.out.println(Thread.currentThread().getName()+" :进入等待。。。");
				this.wait();
				System.out.println(Thread.currentThread().getName()+" :被唤醒!!!");
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		System.out.println(Thread.currentThread().getName()+" :枷锁");
		isLocked = true;
	}
	
	public synchronized void unlock() {
		System.out.println(Thread.currentThread().getName()+" :释放锁");
		this.notify();
		isLocked = false;
	}

}
